{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Jupyter Notebooks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Jupyter notebooks are an interface to a programming language, surrounded by a rich environment for documenting, visualizing, and writing." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.1 Backends" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When you open or create a notebook, you are actually starting two things:\n", "\n", "1. a backend kernel process that will handle the execution of your code\n", "1. a frontend webpage that allows typing in code, saving the notebook, etc.\n", "\n", "The backend kernel can be in any number of programming languages, including Python 2, Python 3, or Scheme. Initially, the backend will start in Python 2, but you can change that after you create the notebook. After you create a new notebook, you will be in the notebook editor frontend (see below). In the upper right-hand corner, simply change the pull-down list from `IPython (Python 2)` to `Scheme`.\n", "\n", "This server is running on a Linux computer. You can also talk directly to this computer by using \"shell magics\" discussed below." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.2 Frontends" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Jupyter Project at Bryn Mawr College will use the web interface. This allows you to edit, document, and execute code in a web browser." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.2.1 Code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using Jupyter, you'll be able to execute code in many computer languages. By default, a newly created notebook will use \"IPython (Python 2)\". You can also install other computer languages. Once you change a notebook's associated language, it will remember your choice, and attempt to startup that language.\n", "\n", "Code is executed by a \"kernel\". We will refer to a language as a kernel in much of the Jupyter documentation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.2.2 Magics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Jupyter uses the word \"magic\" to refer to \"meta commands\". These meta commands are largely independent of the particular kernel you are using. However, the magics for each kernel may differ.\n", "\n", "Below we show some command magics." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 1.2.2.1 Shell commands" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In a Jupyter notebook, you can talk directly to the computer through an operating system shell. To list out the files in the current directy, us the `ls` command:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total 188\n", "-rw-r--r-- 1 dblank dblank 3111 Aug 31 14:51 00 Jupyter Notebooks.ipynb\n", "-rw-r--r-- 1 dblank dblank 18385 Aug 27 06:20 01 Scheme, Introduction.ipynb\n", "drwxrwxr-x 2 dblank dblank 4096 Aug 29 12:54 images\n", "-rw-r--r-- 1 dblank dblank 17195 Aug 30 10:13 Jupyter Help.ipynb\n", "-rw-r--r-- 1 dblank dblank 3015 Aug 29 15:57 Jupyter Magics.ipynb\n", "-rw-r--r-- 1 dblank dblank 92667 Aug 29 13:02 Jupyter Notebook Users Manual.ipynb\n", "-rw-r--r-- 1 dblank dblank 39037 Aug 29 20:42 Jupyter Visualizations.ipynb\n", "-rw-r--r-- 1 dblank dblank 2960 Aug 29 20:36 timeline.html\n", "\n" ] } ], "source": [ "! ls -l" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use `pwd` to \"print working direct\":" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/dblank/Public\n", "\n" ] } ], "source": [ "! pwd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 1.2.2.2 Help commands" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can usually put a question mark before or after an item's name and execute the shell. Usually, one question mark means \"give me a hint about what this is\"; two question marks mean \"give me more details\". You can also press SHIFT+TAB after a word in an expression and see the hint. In these examples, we are using the Calico Scheme kernel: " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "?car" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "??car" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Press SHIFT+TAB with the cursor after the last e in \"define\":" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "(define ...)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 1.2.2.3 Magic commands" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Magic commands start out with either a \"!\", \"?\", or \"%\":" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Line magics:\n", " %cd PATH - change current directory of session\n", " %connect_info - show connection information\n", " %download URL [FILENAME] - download file from URL\n", " %html CODE - display code as HTML\n", " %install_magic URL - download and install magic from URL\n", " %javascript CODE - send code as JavaScript\n", " %latex TEXT - display text as LaTeX\n", " %lsmagic - list the current line and cell magics\n", " %magic - show installed magics\n", " %plot [options] backend - configure plotting for the session.\n", " %reload_magics - reload the magics from the installed files\n", " %shell COMMAND - run the line as a shell command\n", "\n", "Cell magics:\n", " %%file [--append|-a] FILENAME - write contents of cell to file\n", " %%html - display contents of cell as HTML\n", " %%javascript - send contents of cell as JavaScript\n", " %%latex - display contents of cell as LaTeX\n", " %%shell - run the contents of the cell as shell commands\n", " %%time - show time to run cell\n", "\n", "Shell shortcut:\n", " ! COMMAND ... - execute command in shell\n", "\n", "Any cell magic can be made persistent for rest of session by using %%% prefix.\n", "\n", "Help on items:\n", " ??item - get detailed help on item\n", " ?item - get help on item\n", "\n" ] } ], "source": [ "%magic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.3 Documenting code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Please see [Jupyter Notebook Users Manual](http://jupyter.cs.brynmawr.edu/hub/dblank/public/Jupyter%20Notebook%20Users%20Manual.ipynb) for more information on editing and documenting a notebook." ] } ], "metadata": { "kernelspec": { "codemirror_mode": "scheme", "display_name": "Scheme", "language": "scheme", "name": "calico_scheme_kernel" } }, "nbformat": 4, "nbformat_minor": 0 }